<!DOCTYPE html>
<html lang="en">





<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" type="image/png" href="/img/favicon.png">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="My Personal Website For Blog">
  <meta name="author" content="黄宇辉">
  <meta name="keywords" content="learning note,hexo blog">
  <title>Java web:JSP Model - 欢迎参观小灰灰的网站哟 ヾ(◍°∇°◍)ﾉﾞ ~</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/vs2015.min.css" />
  

  


<!-- 主题依赖的图标库，不要自行修改 -->
<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_yg9cfy8wd6.css">

<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_pjno9b9zyxs.css">

<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/js/utils.js" ></script>
</head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>ANONYMOUS</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                Home
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                Archives
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                Tags
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                About
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="view intro-2" id="background" parallax=true
         style="background: url('/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container text-center white-text fadeInUp">
            <span class="h2" id="subtitle">
              
            </span>

            
              
  <div class="mt-3 post-meta">
    <i class="iconfont icon-date-fill" aria-hidden="true"></i>
    <time datetime="2019-05-05 22:11">
      May 5, 2019 pm
    </time>
  </div>


<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      2.7k 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      45
       分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <div class="post-content mx-auto" id="post">
            
            <article class="markdown-body">
              <h2 id="学习笔记-Java-web之JSP-开发模型"><a href="#学习笔记-Java-web之JSP-开发模型" class="headerlink" title="学习笔记 : Java web之JSP 开发模型"></a>学习笔记 : Java web之JSP 开发模型</h2><h3 id="JSP-Model1"><a href="#JSP-Model1" class="headerlink" title="JSP Model1"></a>JSP Model1</h3><p><em>简介 : <code>JSP Model1</code>采用JSP+JavaBean的技术,将页面显示和业务逻辑分开.其中,JSP实现流程控制和页面显示,JavaBean对象封装数据和业务逻辑.这种设计实现了数据,业务逻辑和页面显示的分离,在一定程度上实现了程序开发的模块化,降低了程序修改和维护的难度.</em></p>
<h4 id="JSP-Model1-案例"><a href="#JSP-Model1-案例" class="headerlink" title="JSP Model1 案例"></a>JSP Model1 案例</h4><p><em>案例描述 : 通过一个简单的网络计算器程序来深化对JSP Model1模型的理解.</em></p>
<ol>
<li><p><em>Calculator.java : 封装计算器中的数据,处理业务逻辑.</em></p>
<div class="hljs"><pre><code class="hljs java"><span class="hljs-keyword">package</span> pers.huangyuhui.jspmodel.model1.calculator;

<span class="hljs-keyword">import</span> java.math.BigDecimal;
<span class="hljs-keyword">import</span> java.util.HashMap;
<span class="hljs-keyword">import</span> java.util.Map;
<span class="hljs-keyword">import</span> java.util.regex.Pattern;

<span class="hljs-comment">/**
 * <span class="hljs-doctag">@ClassName</span>: Calculator
 * <span class="hljs-doctag">@Description</span>: 封装计算器中的数据及处理业务逻辑
 * <span class="hljs-doctag">@author</span>: HuangYuhui
 * <span class="hljs-doctag">@date</span>: May 5, 2019 10:10:43 AM
 * 
 */</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Calculator</span> </span>&#123;

	<span class="hljs-keyword">private</span> <span class="hljs-keyword">char</span> operator;
	<span class="hljs-keyword">private</span> String firstNumber;
	<span class="hljs-keyword">private</span> String secondNumber;
	<span class="hljs-keyword">private</span> Map&lt;String, String&gt; errors = <span class="hljs-keyword">new</span> HashMap&lt;String, String&gt;();<span class="hljs-comment">// 封装错误信息</span>

	<span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getFirstNumber</span><span class="hljs-params">()</span> </span>&#123;
		<span class="hljs-keyword">return</span> firstNumber;
	&#125;

	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setFirstNumber</span><span class="hljs-params">(String firstNumber)</span> </span>&#123;
		<span class="hljs-keyword">this</span>.firstNumber = firstNumber;
	&#125;

	<span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getSecondNumber</span><span class="hljs-params">()</span> </span>&#123;
		<span class="hljs-keyword">return</span> secondNumber;
	&#125;

	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setSecondNumber</span><span class="hljs-params">(String secondNumber)</span> </span>&#123;
		<span class="hljs-keyword">this</span>.secondNumber = secondNumber;
	&#125;

	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">char</span> <span class="hljs-title">getOperator</span><span class="hljs-params">()</span> </span>&#123;
		<span class="hljs-keyword">return</span> operator;
	&#125;

	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setOperator</span><span class="hljs-params">(<span class="hljs-keyword">char</span> operator)</span> </span>&#123;
		<span class="hljs-keyword">this</span>.operator = operator;
	&#125;

	<span class="hljs-function"><span class="hljs-keyword">public</span> Map&lt;String, String&gt; <span class="hljs-title">getErrors</span><span class="hljs-params">()</span> </span>&#123;
		<span class="hljs-keyword">return</span> errors;
	&#125;

	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setErrors</span><span class="hljs-params">(Map&lt;String, String&gt; errors)</span> </span>&#123;
		<span class="hljs-keyword">this</span>.errors = errors;
	&#125;

	<span class="hljs-comment">// 运算操作</span>
	<span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">caculate</span><span class="hljs-params">()</span> </span>&#123;
		BigDecimal result = <span class="hljs-keyword">null</span>;
		BigDecimal firstNum = <span class="hljs-keyword">new</span> BigDecimal(firstNumber);
		BigDecimal secondNum = <span class="hljs-keyword">new</span> BigDecimal(secondNumber);

		<span class="hljs-keyword">switch</span> (operator) &#123;
		<span class="hljs-keyword">case</span> <span class="hljs-string">'+'</span>:
			result = firstNum.add(secondNum);
			<span class="hljs-keyword">break</span>;
		<span class="hljs-keyword">case</span> <span class="hljs-string">'-'</span>:
			result = firstNum.subtract(secondNum);
			<span class="hljs-keyword">break</span>;
		<span class="hljs-keyword">case</span> <span class="hljs-string">'*'</span>:
			result = firstNum.multiply(secondNum);
			<span class="hljs-keyword">break</span>;
		<span class="hljs-keyword">case</span> <span class="hljs-string">'/'</span>:
			<span class="hljs-keyword">if</span> (<span class="hljs-string">"0"</span>.equals(secondNumber)) &#123;
				<span class="hljs-comment">// throw new RuntimeException("除数不能为 0 !");</span>
				<span class="hljs-keyword">return</span> <span class="hljs-keyword">null</span>;
			&#125;
			result = firstNum.divide(secondNum);
			<span class="hljs-keyword">break</span>;

		<span class="hljs-keyword">default</span>:
			<span class="hljs-keyword">break</span>;
		&#125;

		<span class="hljs-keyword">return</span> result.toString();
	&#125;

	<span class="hljs-comment">// 验证表单传入的数据是否合法</span>
	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">validate</span><span class="hljs-params">()</span> </span>&#123;
		<span class="hljs-keyword">boolean</span> flag = <span class="hljs-keyword">true</span>;
		Pattern pattern = Pattern.compile(<span class="hljs-string">"\\d+"</span>);<span class="hljs-comment">// 匹配数字</span>
		<span class="hljs-keyword">if</span> (firstNumber == <span class="hljs-keyword">null</span> || <span class="hljs-string">""</span>.equals(firstNumber)) &#123;
			errors.put(<span class="hljs-string">"firstNumberErrorInfo"</span>, <span class="hljs-string">"第一个运算数不能为空 !"</span>);
			flag = <span class="hljs-keyword">false</span>;
		&#125; <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (!pattern.matcher(firstNumber).matches()) &#123;
			errors.put(<span class="hljs-string">"firstNumberErrorInfo"</span>, <span class="hljs-string">"第一个运算数必须为数字 !"</span>);
			flag = <span class="hljs-keyword">false</span>;
		&#125;

		<span class="hljs-keyword">if</span> (secondNumber == <span class="hljs-keyword">null</span> || <span class="hljs-string">""</span>.equals(secondNumber)) &#123;
			errors.put(<span class="hljs-string">"secondNumberErrorInfo"</span>, <span class="hljs-string">"第二个运算数不能为空 !"</span>);
			flag = <span class="hljs-keyword">false</span>;
		&#125; <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (!pattern.matcher(secondNumber).matches()) &#123;
			errors.put(<span class="hljs-string">"secondNumberErrorInfo"</span>, <span class="hljs-string">"第二个运算数必须为数字 !"</span>);
			flag = <span class="hljs-keyword">false</span>;
		&#125; <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-string">"0"</span>.equals(secondNumber)) &#123;
			errors.put(<span class="hljs-string">"secondNumberErrorInfo"</span>, <span class="hljs-string">"被除数不能为 0 !"</span>);
			flag = <span class="hljs-keyword">false</span>;
		&#125;

		<span class="hljs-keyword">return</span> flag;
	&#125;

&#125;</code></pre></div>
</li>
<li><p><em>calculator.jsp : 显示网络计算机的页面.</em></p>
<div class="hljs"><pre><code class="hljs html">&lt;%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.util.Map"%&gt;
&lt;jsp:useBean id="calculator" class="pers.huangyuhui.jspmodel.model1.calculator.Calculator"/&gt;
&lt;jsp:setProperty property="*" name="calculator"/&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
	&lt;head&gt;
		&lt;meta charset="UTF-8"&gt;
		&lt;title&gt;JSP Model 1&lt;/title&gt;
		&lt;style&gt;
			span&#123;
				font-size:13px;
				color:red;
			&#125;
			#main&#123;
				width:600px;
				margin-left: 425px;
			&#125;
			#main tr&#123;
				height:40px;
			&#125;
			#main tr td&#123;
				width: 50px;
			&#125;
			#main tr td input&#123;
				width: 200px;
			&#125;
			.buttom &#123;
				text-align: center;
				padding-top: 25px;
			&#125;
			.buttom .calculate&#123;
				margin-right: 65px;
			&#125;
		&lt;/style&gt;
	&lt;/head&gt;
	&lt;body&gt;
		&lt;h3 align="center"&gt;JSP Mode 1 : 计算器&lt;/h3&gt;&lt;hr/&gt;
			&lt;form action="" method="post"&gt;
				&lt;table id="main"&gt;
					&lt;tr&gt;
						&lt;td&gt;	第一个运算数&lt;/td&gt;
						&lt;td &gt;
							&lt;input type="text" name="firstNumber"/&gt;
							&lt;span&gt;$&#123;errors.firstNumberErrorInfo &#125;&lt;/span&gt;
						&lt;/td&gt;
					&lt;/tr&gt;
					&lt;tr&gt;
						&lt;td&gt;	运算符&lt;/td&gt;
						&lt;td&gt;
							&lt;select name="operator" style="margin-left:65px"&gt;
								&lt;option value="+"&gt;+&lt;/option&gt;
								&lt;option value="-"&gt;-&lt;/option&gt;
								&lt;option value="*"&gt;*&lt;/option&gt;
								&lt;option value="/"&gt;/&lt;/option&gt;
							&lt;/select&gt;
						&lt;/td&gt;
					&lt;/tr&gt;
					&lt;tr&gt;
						&lt;td&gt;第二个运算符&lt;/td&gt;
						&lt;td&gt;
							&lt;input type="text" name="secondNumber"/&gt;
							&lt;span&gt;$&#123;errors.secondNumberErrorInfo &#125;&lt;/span&gt;
						&lt;/td&gt;
					&lt;/tr&gt;
					&lt;tr&gt;
						&lt;td&gt;运算结果: &lt;/td&gt;
						&lt;td&gt;
							&lt;%
								Map&lt;String,String&gt; errorInfo = calculator.getErrors();
								if(calculator.validate())&#123;
									pageContext.getSession().removeAttribute("errors");
							%&gt;
							&lt;font color="green"&gt;
								&lt;jsp:getProperty property="firstNumber" name="calculator"/&gt;
								&lt;jsp:getProperty property="operator" name="calculator"/&gt;
								&lt;jsp:getProperty property="secondNumber" name="calculator"/&gt;
								= &lt;%=calculator.caculate() %&gt;
							&lt;%
								&#125;else&#123;
									pageContext.getSession().setAttribute("errors",errorInfo);
								&#125;
							%&gt;
							&lt;/font&gt;
						&lt;/td&gt;
					&lt;/tr&gt;
				&lt;/table&gt;
				&lt;div class="buttom"&gt;
					&lt;input class="calculate" type="submit" value="计算"/&gt;
					&lt;input type="reset" value="重置"/&gt;
				&lt;/div&gt;		
			&lt;/form&gt;
	&lt;/body&gt;
&lt;/html&gt;</code></pre></div>
</li>
<li><p><em>程序运行效果示例图.</em><br><img src="/2019/05/05/Java-web-JSP-Model/JSPModel1%E6%A1%88%E4%BE%8B-%E8%AE%A1%E7%AE%97%E5%99%A8%E9%A1%B5%E9%9D%A2.PNG" srcset="/img/loading.gif" alt=" "></p>
</li>
</ol>
<h3 id="JSP-Model2"><a href="#JSP-Model2" class="headerlink" title="JSP Model2"></a>JSP Model2</h3><p><em>简介 : <code>JSP Model2</code>架构模型采用JSP+Servlet+JavaBean技术,其将<code>JSP Model1</code>中JSP页面里的流程控制代码提取出来.封装到Servlet中,从而实现了整个程序页面显示,流程控制和业务逻辑的分离.实际上JSP Model2就是<code>MVC</code>设计模式,其中控制器(<code>Colltroller</code>)的角色由Servlet实现,视图(<code>View</code>)的角色由JSP实现,模型(<code>Model</code>)的角色由JavaBean实现.</em></p>
<h4 id="JSP-Model2-案例"><a href="#JSP-Model2-案例" class="headerlink" title="JSP Model2 案例"></a>JSP Model2 案例</h4><p><em>案例描述 : 按照<code>JSP Model2</code>的模型思想编写一个用户注册的简单示例程序.</em></p>
<ol>
<li><p><em>UserBean.java : 封装用户的注册信息.</em></p>
<div class="hljs"><pre><code class="hljs java"><span class="hljs-keyword">package</span> pers.huangyuhui.jspmodel.model2.register;

<span class="hljs-comment">/**
 * <span class="hljs-doctag">@ClassName</span>: UserBean
 * <span class="hljs-doctag">@Description</span>: 封装用户注册信息
 * <span class="hljs-doctag">@author</span>: HuangYuhui
 * <span class="hljs-doctag">@date</span>: May 5, 2019 4:35:21 PM
 * 
 */</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UserBean</span> </span>&#123;

	<span class="hljs-keyword">private</span> String name;
	<span class="hljs-keyword">private</span> String password;
	<span class="hljs-keyword">private</span> String email;

	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">UserBean</span><span class="hljs-params">(String name, String password, String email)</span> </span>&#123;
		<span class="hljs-keyword">super</span>();
		<span class="hljs-keyword">this</span>.name = name;
		<span class="hljs-keyword">this</span>.password = password;
		<span class="hljs-keyword">this</span>.email = email;
	&#125;

	<span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getName</span><span class="hljs-params">()</span> </span>&#123;
		<span class="hljs-keyword">return</span> name;
	&#125;

	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setName</span><span class="hljs-params">(String name)</span> </span>&#123;
		<span class="hljs-keyword">this</span>.name = name;
	&#125;

	<span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getPassword</span><span class="hljs-params">()</span> </span>&#123;
		<span class="hljs-keyword">return</span> password;
	&#125;

	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setPassword</span><span class="hljs-params">(String password)</span> </span>&#123;
		<span class="hljs-keyword">this</span>.password = password;
	&#125;

	<span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getEmail</span><span class="hljs-params">()</span> </span>&#123;
		<span class="hljs-keyword">return</span> email;
	&#125;

	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setEmail</span><span class="hljs-params">(String email)</span> </span>&#123;
		<span class="hljs-keyword">this</span>.email = email;
	&#125;

&#125;</code></pre></div>
</li>
<li><p><em>RegisterFormBean.java : 封装并效验注册表单信息的JavaBean.</em></p>
<div class="hljs"><pre><code class="hljs java"><span class="hljs-keyword">package</span> pers.huangyuhui.jspmodel.model2.register;

<span class="hljs-keyword">import</span> java.util.HashMap;
<span class="hljs-keyword">import</span> java.util.Map;

<span class="hljs-comment">/**
 * <span class="hljs-doctag">@ClassName</span>: RegisterFormBean
 * <span class="hljs-doctag">@Description</span>: 效验注册表单信息
 * <span class="hljs-doctag">@author</span>: HuangYuhui
 * <span class="hljs-doctag">@date</span>: May 5, 2019 4:37:33 PM
 * 
 */</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">RegisterFormBean</span> </span>&#123;

	<span class="hljs-keyword">private</span> String name;
	<span class="hljs-keyword">private</span> String password;
	<span class="hljs-keyword">private</span> String password2;
	<span class="hljs-keyword">private</span> String email;

	<span class="hljs-comment">// 存储验证表单时发生的错误信息</span>
	<span class="hljs-keyword">private</span> Map&lt;String, String&gt; errors = <span class="hljs-keyword">new</span> HashMap&lt;String, String&gt;();

	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">RegisterFormBean</span><span class="hljs-params">(String name, String password, String password2, String email)</span> </span>&#123;
		<span class="hljs-keyword">super</span>();
		<span class="hljs-keyword">this</span>.name = name;
		<span class="hljs-keyword">this</span>.password = password;
		<span class="hljs-keyword">this</span>.password2 = password2;
		<span class="hljs-keyword">this</span>.email = email;
	&#125;

	<span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getName</span><span class="hljs-params">()</span> </span>&#123;
		<span class="hljs-keyword">return</span> name;
	&#125;

	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setName</span><span class="hljs-params">(String name)</span> </span>&#123;
		<span class="hljs-keyword">this</span>.name = name;
	&#125;

	<span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getPassword</span><span class="hljs-params">()</span> </span>&#123;
		<span class="hljs-keyword">return</span> password;
	&#125;

	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setPassword</span><span class="hljs-params">(String password)</span> </span>&#123;
		<span class="hljs-keyword">this</span>.password = password;
	&#125;

	<span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getPassword2</span><span class="hljs-params">()</span> </span>&#123;
		<span class="hljs-keyword">return</span> password2;
	&#125;

	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setPassword2</span><span class="hljs-params">(String password2)</span> </span>&#123;
		<span class="hljs-keyword">this</span>.password2 = password2;
	&#125;

	<span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getEmail</span><span class="hljs-params">()</span> </span>&#123;
		<span class="hljs-keyword">return</span> email;
	&#125;

	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setEmail</span><span class="hljs-params">(String email)</span> </span>&#123;
		<span class="hljs-keyword">this</span>.email = email;
	&#125;

	<span class="hljs-comment">// 获取注册信息效验时发生的错误信息</span>
	<span class="hljs-function"><span class="hljs-keyword">public</span> Map&lt;String, String&gt; <span class="hljs-title">getErrors</span><span class="hljs-params">()</span> </span>&#123;
		<span class="hljs-keyword">return</span> errors;
	&#125;

	<span class="hljs-comment">// 添加注册信息效验时发生的错误信息</span>
	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setErrorsMsg</span><span class="hljs-params">(String error, String errorMsg)</span> </span>&#123;
		<span class="hljs-keyword">if</span> ((error) != <span class="hljs-keyword">null</span> &amp;&amp; (errorMsg != <span class="hljs-keyword">null</span>)) &#123;
			errors.put(error, errorMsg);
		&#125;
	&#125;

	<span class="hljs-comment">// 校验用户注册信息</span>
	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">validate</span><span class="hljs-params">()</span> </span>&#123;
		<span class="hljs-keyword">boolean</span> flag = <span class="hljs-keyword">true</span>;

		<span class="hljs-keyword">if</span> (name == <span class="hljs-keyword">null</span> || name.trim().equals(<span class="hljs-string">""</span>)) &#123;
			errors.put(<span class="hljs-string">"nameErrorInfo"</span>, <span class="hljs-string">"请输入用户名 !"</span>);
			flag = <span class="hljs-keyword">false</span>;
		&#125;

		<span class="hljs-keyword">if</span> (password == <span class="hljs-keyword">null</span> || password.trim().equals(<span class="hljs-string">""</span>)) &#123;
			errors.put(<span class="hljs-string">"passwordErrorInfo"</span>, <span class="hljs-string">"请输入密码 !"</span>);
			flag = <span class="hljs-keyword">false</span>;
		&#125; <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (password.length() &gt; <span class="hljs-number">16</span> || password.length() &lt; <span class="hljs-number">6</span>) &#123;
			errors.put(<span class="hljs-string">"passwordErrorInfo"</span>, <span class="hljs-string">"请输入6-12位的密码 !"</span>);
			flag = <span class="hljs-keyword">false</span>;
		&#125;

		<span class="hljs-keyword">if</span> (password != <span class="hljs-keyword">null</span> &amp;&amp; !password.equals(password2)) &#123;
			errors.put(<span class="hljs-string">"password2ErrorInfo"</span>, <span class="hljs-string">"两次输入的密码不相同 !"</span>);
			flag = <span class="hljs-keyword">false</span>;
		&#125;

		<span class="hljs-keyword">if</span> (email == <span class="hljs-keyword">null</span> || email.trim().equals(<span class="hljs-string">""</span>)) &#123;
			errors.put(<span class="hljs-string">"emailErrorInfo"</span>, <span class="hljs-string">"请输入邮箱地址 !"</span>);
			flag = <span class="hljs-keyword">false</span>;
		&#125; <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (!email.matches(<span class="hljs-string">"[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+"</span>)) &#123;
			errors.put(<span class="hljs-string">"emailErrorInfo"</span>, <span class="hljs-string">"邮箱地址格式错误 !"</span>);
			flag = <span class="hljs-keyword">false</span>;
		&#125;

		<span class="hljs-keyword">return</span> flag;
	&#125;

&#125;</code></pre></div>
</li>
<li><p><em>DBUtil.java : 访问数据库的辅助类,充当DAO.</em></p>
<div class="hljs"><pre><code class="hljs java"><span class="hljs-keyword">package</span> pers.huangyuhui.jspmodel.model2.register;

<span class="hljs-keyword">import</span> java.util.HashMap;

<span class="hljs-comment">/**
 * <span class="hljs-doctag">@ClassName</span>: DBUtil
 * <span class="hljs-doctag">@Description</span>: 模拟数据库,充当DAO
 * <span class="hljs-doctag">@author</span>: HuangYuhui
 * <span class="hljs-doctag">@date</span>: May 5, 2019 4:50:10 PM
 * 
 */</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">DBUtil</span> </span>&#123;

	<span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> DBUtil instance = <span class="hljs-keyword">new</span> DBUtil();
	<span class="hljs-keyword">private</span> HashMap&lt;String, UserBean&gt; users = <span class="hljs-keyword">new</span> HashMap&lt;String, UserBean&gt;();

	<span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-title">DBUtil</span><span class="hljs-params">()</span> </span>&#123;
		<span class="hljs-comment">// 向数据库中添加一条用户数据</span>
		UserBean firstUser = <span class="hljs-keyword">new</span> UserBean(<span class="hljs-string">"YUbuntu0109"</span>, <span class="hljs-string">"myPassword"</span>, <span class="hljs-string">"Gentleman_0109@outlook.com"</span>);
		users.put(<span class="hljs-string">"YUbuntu0109"</span>, firstUser);
	&#125;

	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> DBUtil <span class="hljs-title">getInstance</span><span class="hljs-params">()</span> </span>&#123;
		<span class="hljs-keyword">return</span> instance;
	&#125;

	<span class="hljs-comment">// 获取数据库中指定用户名的数据</span>
	<span class="hljs-function"><span class="hljs-keyword">public</span> UserBean <span class="hljs-title">getUser</span><span class="hljs-params">(String userName)</span> </span>&#123;

		UserBean user = users.get(userName);
		<span class="hljs-keyword">return</span> user;
	&#125;

	<span class="hljs-comment">// 向数据库中添加新的用户数据</span>
	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">insertUser</span><span class="hljs-params">(UserBean user)</span> </span>&#123;
		<span class="hljs-keyword">if</span> (user == <span class="hljs-keyword">null</span>) &#123;
			<span class="hljs-keyword">return</span> <span class="hljs-keyword">false</span>;
		&#125;

		String userName = user.getName();
		<span class="hljs-keyword">if</span> (users.get(userName) != <span class="hljs-keyword">null</span>) &#123;
			<span class="hljs-keyword">return</span> <span class="hljs-keyword">false</span>;
		&#125;
		users.put(userName, user);
		<span class="hljs-keyword">return</span> <span class="hljs-keyword">true</span>;
	&#125;

&#125;</code></pre></div>
</li>
<li><p><em>ControllerServlet.java : 控制器,负责处理用户注册的请求.</em></p>
<div class="hljs"><pre><code class="hljs java"><span class="hljs-keyword">package</span> pers.huangyuhui.jspmodel.model2.register;

<span class="hljs-keyword">import</span> java.io.IOException;

<span class="hljs-keyword">import</span> javax.servlet.ServletException;
<span class="hljs-keyword">import</span> javax.servlet.annotation.WebServlet;
<span class="hljs-keyword">import</span> javax.servlet.http.HttpServlet;
<span class="hljs-keyword">import</span> javax.servlet.http.HttpServletRequest;
<span class="hljs-keyword">import</span> javax.servlet.http.HttpServletResponse;

<span class="hljs-comment">/**
 * <span class="hljs-doctag">@ClassName</span>: ColltrollerServlet
 * <span class="hljs-doctag">@Description</span>: 处理用户注册请求
 * <span class="hljs-doctag">@author</span>: HuangYuhui
 * <span class="hljs-doctag">@date</span>: May 5, 2019 5:01:46 PM
 *
 */</span>
<span class="hljs-meta">@WebServlet</span>(<span class="hljs-string">"/ControllerServlet"</span>)
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ControllerServlet</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">HttpServlet</span> </span>&#123;
	<span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">long</span> serialVersionUID = <span class="hljs-number">1L</span>;

	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">ControllerServlet</span><span class="hljs-params">()</span> </span>&#123;
		<span class="hljs-keyword">super</span>();
	&#125;

	<span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title">doGet</span><span class="hljs-params">(HttpServletRequest request, HttpServletResponse response)</span>
			<span class="hljs-keyword">throws</span> ServletException, IOException </span>&#123;

		request.setCharacterEncoding(<span class="hljs-string">"utf-8"</span>);
		response.setContentType(<span class="hljs-string">"text/html;charset=utf-8"</span>);

		String name = request.getParameter(<span class="hljs-string">"userName"</span>);
		String password = request.getParameter(<span class="hljs-string">"userPassword"</span>);
		String password2 = request.getParameter(<span class="hljs-string">"userPassword2"</span>);
		String email = request.getParameter(<span class="hljs-string">"userEmail"</span>);

		<span class="hljs-comment">// 效验用户提交的注册表单信息</span>
		RegisterFormBean registerFormBean = <span class="hljs-keyword">new</span> RegisterFormBean(name, password, password2, email);
		<span class="hljs-keyword">if</span> (!registerFormBean.validate()) &#123;
			request.setAttribute(<span class="hljs-string">"registerFromBean"</span>, registerFormBean);
			request.getRequestDispatcher(<span class="hljs-string">"/register.jsp"</span>).forward(request, response);
			<span class="hljs-keyword">return</span>;
		&#125;

		<span class="hljs-comment">// 存储用户注册信息</span>
		UserBean userBean = <span class="hljs-keyword">new</span> UserBean(name, password2, email);
		<span class="hljs-keyword">if</span> (!DBUtil.getInstance().insertUser(userBean)) &#123;
			request.setAttribute(<span class="hljs-string">"BDUtilErrorInfo"</span>, <span class="hljs-string">"抱歉! 你注册的用户名已存在啦 !"</span>);
			request.setAttribute(<span class="hljs-string">"registerFromBean"</span>, registerFormBean);
			request.getRequestDispatcher(<span class="hljs-string">"/register.jsp"</span>).forward(request, response);
			<span class="hljs-keyword">return</span>;
		&#125;

		request.getSession().setAttribute(<span class="hljs-string">"userBean"</span>, userBean);
		response.getWriter().print(<span class="hljs-string">"注册成功啦 ! 三秒后将自动跳转到用户注册信息的页面  !"</span>);
		response.setHeader(<span class="hljs-string">"refresh"</span>, <span class="hljs-string">"3;url=registerInfo.jsp"</span>);

	&#125;

	<span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title">doPost</span><span class="hljs-params">(HttpServletRequest request, HttpServletResponse response)</span>
			<span class="hljs-keyword">throws</span> ServletException, IOException </span>&#123;
		doGet(request, response);
	&#125;

&#125;</code></pre></div>
</li>
<li><p><em>register.jsp : 用户注册页面.</em></p>
<div class="hljs"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">%@</span> <span class="hljs-attr">page</span> <span class="hljs-attr">language</span>=<span class="hljs-string">"java"</span> <span class="hljs-attr">contentType</span>=<span class="hljs-string">"text/html; charset=UTF-8"</span> <span class="hljs-attr">pageEncoding</span>=<span class="hljs-string">"UTF-8"</span>%&gt;</span>
<span class="hljs-meta">&lt;!DOCTYPE html&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>JSP Model 2<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">style</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/css"</span>&gt;</span><span class="css">
			<span class="hljs-selector-tag">h3</span>&#123;
				<span class="hljs-attribute">text-align</span>:center;
			&#125;
			<span class="hljs-selector-id">#main</span>&#123;
				<span class="hljs-attribute">width</span>:<span class="hljs-number">600px</span>;
				<span class="hljs-attribute">margin-left</span>: <span class="hljs-number">450px</span>;
			&#125;
			<span class="hljs-selector-id">#main</span> <span class="hljs-selector-tag">tr</span>&#123;
				<span class="hljs-attribute">height</span>:<span class="hljs-number">40px</span>;
			&#125;
			<span class="hljs-selector-id">#main</span> <span class="hljs-selector-tag">tr</span> <span class="hljs-selector-tag">td</span>&#123;
				<span class="hljs-attribute">width</span>: <span class="hljs-number">50px</span>;
			&#125;
			<span class="hljs-selector-id">#main</span> <span class="hljs-selector-tag">tr</span> <span class="hljs-selector-tag">td</span> <span class="hljs-selector-tag">input</span>&#123;
				<span class="hljs-attribute">width</span>: <span class="hljs-number">200px</span>;
			&#125;
			<span class="hljs-selector-tag">span</span>&#123;
				<span class="hljs-attribute">font-size</span>:<span class="hljs-number">13px</span>;
				<span class="hljs-attribute">color</span>:red;
			&#125;
			<span class="hljs-selector-class">.buttom</span> &#123;
				<span class="hljs-attribute">text-align</span>: center;
				<span class="hljs-attribute">padding-top</span>: <span class="hljs-number">25px</span>;
			&#125;
			<span class="hljs-selector-class">.buttom</span> <span class="hljs-selector-class">.register</span>&#123;
				<span class="hljs-attribute">margin-right</span>: <span class="hljs-number">70px</span>;
			&#125;
		</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
	<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>用户注册页面<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">hr</span>/&gt;</span>
			<span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">"ControllerServlet"</span> <span class="hljs-attr">method</span>=<span class="hljs-string">"post"</span>&gt;</span>
				<span class="hljs-tag">&lt;<span class="hljs-name">table</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"main"</span>&gt;</span>
					 <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
					 	<span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>用户名<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
					 	<span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>
					 		<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"userName"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"$&#123;registerFromBean.name &#125;"</span>/&gt;</span>
					 		<span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>
					 			$&#123;registerFromBean.errors.nameErrorInfo &#125;
					 			$&#123;BDUtilErrorInfo &#125;
					 		<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
					 	<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
					 <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
					 <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
					 	<span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>密码<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
					 	<span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>
					 		<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"password"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"userPassword"</span> /&gt;</span>
					 		<span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>
								$&#123;registerFromBean.errors.passwordErrorInfo &#125;
					 		<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
					 	<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
					 <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
					 <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
					 	<span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>确认密码<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
					 	<span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>
					 		<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"password"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"userPassword2"</span>/&gt;</span>
					 		<span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>
					 			$&#123;registerFromBean.errors.password2ErrorInfo &#125;
					 		<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
					 	<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
					 <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
					 <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
					 	<span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>邮箱<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
					 	<span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>
					 		<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"userEmail"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"$&#123;registerFromBean.email &#125;"</span>/&gt;</span>
					 		<span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>
					 			$&#123;registerFromBean.errors.emailErrorInfo &#125;
					 		<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
					 	<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
					 <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
				<span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span>
				<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"buttom"</span>&gt;</span>
					<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"register"</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"注册"</span>/&gt;</span>
					<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"reset"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"重置"</span>/&gt;</span>
				<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
			<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
	<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span></code></pre></div>
</li>
<li><p><em>registerInfo.jsp : 用户注册成功页面.</em></p>
<div class="hljs"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">%@</span> <span class="hljs-attr">page</span> <span class="hljs-attr">language</span>=<span class="hljs-string">"java"</span> <span class="hljs-attr">contentType</span>=<span class="hljs-string">"text/html; charset=UTF-8"</span> <span class="hljs-attr">pageEncoding</span>=<span class="hljs-string">"UTF-8"</span>%&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">%@taglib</span> <span class="hljs-attr">prefix</span>=<span class="hljs-string">"c"</span> <span class="hljs-attr">uri</span>=<span class="hljs-string">"http://java.sun.com/jsp/jstl/core"</span>%&gt;</span>
<span class="hljs-meta">&lt;!DOCTYPE html&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>JSP Model 2<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
	<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">h3</span> <span class="hljs-attr">align</span>=<span class="hljs-string">"center"</span>&gt;</span>JSP Mode2 : 用户注册信息<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">hr</span>/&gt;</span>
			<span class="hljs-tag">&lt;<span class="hljs-name">c:choose</span>&gt;</span>
				<span class="hljs-tag">&lt;<span class="hljs-name">c:when</span> <span class="hljs-attr">test</span>=<span class="hljs-string">"$&#123;sessionScope.userBean == null  &#125;"</span>&gt;</span>
					<span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"$&#123;pageContext.request.contextPath &#125;/register.jsp"</span>&gt;</span>你还未注册! 请注册哟ヾ(●´∀｀●) ~<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
				<span class="hljs-tag">&lt;/<span class="hljs-name">c:when</span>&gt;</span>			
				<span class="hljs-tag">&lt;<span class="hljs-name">c:otherwise</span>&gt;</span>
					<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">align</span>=<span class="hljs-string">"center"</span>&gt;</span>
						<span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>你的姓名: $&#123;sessionScope.userBean.name &#125;<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
						<span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>你的邮箱: $&#123;sessionScope.userBean.email &#125;<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
					<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
				<span class="hljs-tag">&lt;/<span class="hljs-name">c:otherwise</span>&gt;</span>
			<span class="hljs-tag">&lt;/<span class="hljs-name">c:choose</span>&gt;</span>
	<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span></code></pre></div>
</li>
<li><p><em>程序运行效果示例图.</em><br><img src="/2019/05/05/Java-web-JSP-Model/JSPModel2%E6%A1%88%E4%BE%8B-%E7%94%A8%E6%88%B7%E6%B3%A8%E5%86%8C%E9%A1%B5%E9%9D%A2.PNG" srcset="/img/loading.gif" alt=" "><br><img src="/2019/05/05/Java-web-JSP-Model/JSPModel2%E6%A1%88%E4%BE%8B-%E7%94%A8%E6%88%B7%E6%B3%A8%E5%86%8C%E4%BF%A1%E6%81%AF%E9%A1%B5%E9%9D%A2.PNG" srcset="/img/loading.gif" alt=" "></p>
</li>
</ol>

            </article>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/Java-web/">Java web</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" target="_blank" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！</p>
              
              
                <div class="post-prevnext row">
                  <div class="post-prev col-6">
                    
                    
                      <a href="/2019/05/09/Hi-Spring/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Hi Spring ~</span>
                        <span class="visible-mobile">Previous</span>
                      </a>
                    
                  </div>
                  <div class="post-next col-6">
                    
                    
                      <a href="/2019/05/02/VOA-Critics-Praise-New-and-Last-Avengers-Series-Film/">
                        <span class="hidden-mobile">VOA:Critics Praise New and Last Avengers Series Film</span>
                        <span class="visible-mobile">Next</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </div>
                </div>
              
            </div>

            
          </div>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;TOC</p>
  <div id="tocbot"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">Search</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">keyword</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  

  <footer class="mt-5">
  <div class="text-center py-3">
    <div>
      <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a>
      <i class="iconfont icon-love"></i>
      <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener">
        <span>Fluid</span></a>
    </div>
    
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


    

    
  </div>
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/main.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/lazyload.js" ></script>
  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/js/clipboard-use.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: 'article.markdown-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "Java web:JSP Model&nbsp;",
      ],
      cursorChar: "_",
      typeSpeed: 70,
      loop: false,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "hover",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    var path = "/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>







  
  
    <script>
      !function (e, t, a) {
        function r() {
          for (var e = 0; e < s.length; e++) s[e].alpha <= 0 ? (t.body.removeChild(s[e].el), s.splice(e, 1)) : (s[e].y--, s[e].scale += .004, s[e].alpha -= .013, s[e].el.style.cssText = "left:" + s[e].x + "px;top:" + s[e].y + "px;opacity:" + s[e].alpha + ";transform:scale(" + s[e].scale + "," + s[e].scale + ") rotate(45deg);background:" + s[e].color + ";z-index:99999");
          requestAnimationFrame(r)
        }

        function n() {
          var t = "function" == typeof e.onclick && e.onclick;
          e.onclick = function (e) {
            t && t(), o(e)
          }
        }

        function o(e) {
          var a = t.createElement("div");
          a.className = "heart", s.push({
            el: a,
            x: e.clientX - 5,
            y: e.clientY - 5,
            scale: 1,
            alpha: 1,
            color: c()
          }), t.body.appendChild(a)
        }

        function i(e) {
          var a = t.createElement("style");
          a.type = "text/css";
          try {
            a.appendChild(t.createTextNode(e))
          } catch (t) {
            a.styleSheet.cssText = e
          }
          t.getElementsByTagName("head")[0].appendChild(a)
        }

        function c() {
          return "rgb(" + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + ")"
        }

        var s = [];
        e.requestAnimationFrame = e.requestAnimationFrame || e.webkitRequestAnimationFrame || e.mozRequestAnimationFrame || e.oRequestAnimationFrame || e.msRequestAnimationFrame || function (e) {
          setTimeout(e, 1e3 / 60)
        }, i(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"), n(), r()
      }(window, document);
    </script>
  














</body>
</html>
